package com.health.util;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.List;

import com.health.model.BloodPressure;
import com.health.model.User;
import com.health.service.impl.BloodPressureServiceImpl;

public class PKGenerator {
	private static String userId = "";
	private static String pressureId = "";
	/**
	 * userPK(id)生成规则
	 * 邮箱_姓名_注册时间
	 * */
	public static String userIdGenerator(User user) {
		Calendar c =  Calendar.getInstance();
		c.setTime(user.getRegistertime());
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH) + 1;//Calendar里的月份从0开始
		int day = c.get(Calendar.DATE);
		int hour = c.get(Calendar.HOUR);
		int min = c.get(Calendar.MINUTE);
		int sec = c.get(Calendar.SECOND);
//		int MI = c.get(Calendar.MILLISECOND);
		
//		String genderText = "" ;
//		if(user.getGender() == 0) {
//			genderText = "male";
//		} else if(user.getGender() == 1) {
//			genderText = "female";
//		}
//		Random random = new Random();
//		userId = year + "-" + month + "-" + day + "_" + 
//				hour + ":" + min + ":" + sec + "_" + 
//				genderText + "_" + 
//				name + 
//				random.nextInt(9);
		userId = user.getEmail() + "_" +user.getName() + "_" + 
				year + "-" + month + "-" + day + "_" + hour + ":" + min + ":" + sec; 
		return userId;
	}
	
	/**
	 * 血压PK(id)生成规则:
	 * 测试时间_用户姓名
	 * */
	public static String bloodPressureIdGenerator(BloodPressure p) {
		//检测的时间
		Timestamp time = p.getExamTime();
		BloodPressureServiceImpl service = new BloodPressureServiceImpl();
		String userId = p.getUserId();
		pressureId = time + "_" + userId;
		return pressureId;
	}
}
